package edu.nf.relaxenjoy.web.controller.app;

import com.github.pagehelper.PageInfo;
import edu.nf.relaxenjoy.common.result.ResultVO;
import edu.nf.relaxenjoy.domain.vo.CategoryVo;
import edu.nf.relaxenjoy.domain.vo.PostVo;
import edu.nf.relaxenjoy.service.CategoryService;
import edu.nf.relaxenjoy.web.controller.BaseController;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhu
 * @date 2024-12-20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/category")
@Api(tags="分类模块")
public class CategoryController extends BaseController {

    private final CategoryService categoryService;

    /**
     * 得到所有分类，返回树形结构
     *
     * @return
     */
    @RequestMapping("getTreeCategory")
    public ResultVO getTreeCategory() {
        List<CategoryVo> categoryList = categoryService.getTreeCategory();
        return success(categoryList);
    }

    /**
     * 通过分类获取所有的图片
     *
     * @param page
     * @param limit
     * @param id
     * @param type
     * @return
     */
    @RequestMapping("getImgListByCategory/{page}/{limit}")
    public ResultVO getImgListByCategory(@PathVariable long page, @PathVariable long limit, String id, Integer type) {
        PageInfo<PostVo> pageInfo = categoryService.getPostListByCategory(page, limit, id, type);
        return success(pageInfo);
    }

}
